package com.gc.business.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gc.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.gc.business.mapper.IntegralConfigMapper;
import com.gc.business.domain.IntegralConfig;
import com.gc.business.service.IIntegralConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;

/**
 * 积分配置 服务层实现
 * 
 * @author liujinteng
 * @date 2021-01-04
 */
@Slf4j
@Service
public class IntegralConfigServiceImpl extends ServiceImpl<IntegralConfigMapper, IntegralConfig> implements IIntegralConfigService {

    @Override
    public List<IntegralConfig> list(IntegralConfig integralConfig){
        LambdaQueryWrapper<IntegralConfig> wrapper = new LambdaQueryWrapper<>();
        if(integralConfig != null){
            if(StringUtils.isNotEmpty(integralConfig.getConfigId())){
                wrapper.eq(IntegralConfig::getConfigId, integralConfig.getConfigId());
            }
            if(StringUtils.isNotEmpty(integralConfig.getCompanyId())){
                wrapper.eq(IntegralConfig::getCompanyId, integralConfig.getCompanyId());
            }
            if(StringUtils.isNotEmpty(integralConfig.getReportFault())){
                wrapper.eq(IntegralConfig::getReportFault, integralConfig.getReportFault());
            }
            if(StringUtils.isNotEmpty(integralConfig.getReportTiring())){
                wrapper.eq(IntegralConfig::getReportTiring, integralConfig.getReportTiring());
            }
            if(StringUtils.isNotEmpty(integralConfig.getFaultRepair())){
                wrapper.eq(IntegralConfig::getFaultRepair, integralConfig.getFaultRepair());
            }
            if(StringUtils.isNotEmpty(integralConfig.getElevatorUpkeep())){
                wrapper.eq(IntegralConfig::getElevatorUpkeep, integralConfig.getElevatorUpkeep());
            }
            if(StringUtils.isNotEmpty(integralConfig.getIntegralRules())){
                wrapper.eq(IntegralConfig::getIntegralRules, integralConfig.getIntegralRules());
            }
            if(StringUtils.isNotEmpty(integralConfig.getCreateBy())){
                wrapper.eq(IntegralConfig::getCreateBy, integralConfig.getCreateBy());
            }
            if(StringUtils.isNotEmpty(integralConfig.getCreateTime())){
                wrapper.eq(IntegralConfig::getCreateTime, integralConfig.getCreateTime());
            }
            if(StringUtils.isNotEmpty(integralConfig.getUpdateBy())){
                wrapper.eq(IntegralConfig::getUpdateBy, integralConfig.getUpdateBy());
            }
            if(StringUtils.isNotEmpty(integralConfig.getUpdateTime())){
                wrapper.eq(IntegralConfig::getUpdateTime, integralConfig.getUpdateTime());
            }
            if(StringUtils.isNotEmpty(integralConfig.getRemark())){
                wrapper.eq(IntegralConfig::getRemark, integralConfig.getRemark());
            }
        }
        return baseMapper.selectList(wrapper);
    }

    /**
     * 获取积分
     * @param attrId 归属ID
     * @param type 1:上报故障;2:上报困人;3:故障维修;4:电梯保养
     * @return
     */
    @Override
    public String getScoreByType(Long attrId,String type) {
        LambdaQueryWrapper<IntegralConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(IntegralConfig::getCompanyId, attrId);
        IntegralConfig integralConfig = baseMapper.selectOne(wrapper);
        if (integralConfig == null){
            return "0";
        }
        String score = "";
        if (type == "1"){
            score = integralConfig.getReportFault().toString();
        }else if (type == "2"){
            score = integralConfig.getReportTiring().toString();
        }else if (type == "3"){
            score = integralConfig.getFaultRepair().toString();
        }else if (type == "4"){
            score = integralConfig.getElevatorUpkeep().toString();
        }
        return score;
    }
}
